Stefan Kunz
September 27, 2022
---
title: Overview pesticide information
author:
- name: Stefan Kunz
date: last-modified
format:
html:
self-contained: true
number-sections: false
number-depth: 3
anchor-sections: true
code-tools: true
code-fold: false
code-link: false
code-block-bg: "#f1f3f5"
code-block-border-left: "#31BAE9"
mainfont: Source Sans Pro
theme: journal
toc: true
toc-depth: 3
toc-location: left
captions: true
cap-location: margin
table-captions: true
tbl-cap-location: margin
reference-location: margin
comments:
hypothesis: true
execute:
warning: false
message: false
echo : false
editor: visual
editor_options:
chunk_output_type: console
---
```{r}
# ____________________________________________________________________
# Preprocessing & plotting of pesticida data for the RSQA
# TODO:
# - Plot chemical concentrations
# - Unit of Cmax?
# ____________________________________________________________________
source("/home/kunzst/Dokumente/Projects/Trait_DB/Trait-group-environment-relationships/R/Set_up.R")
```
```{r}
rsqa_cmax <- read_xlsx(file.path(data_in, "Chemicals", "RSQA Cmax only data.xlsx"))
setDT(rsqa_cmax)
# subset to sites where biological samples (inverts) have been taken
rsqa_cmax <- rsqa_cmax[Has.Inverts.x == "y", ]
# For now do not consider sediment data
rsqa_cmax <- rsqa_cmax[, .SD, .SDcols = patterns("TSTAID|\\.x|\\_Cmax")]
# Some of the columns containing pesticide information are characters
char_tvars <- names(Filter(is.character, rsqa_cmax[, .SD, .SDcols = patterns("\\_Cmax")]))
rsqa_cmax[, (char_tvars) := as.numeric(get(char_tvars))]
# LF
rsqa_cmax_lf <- melt(rsqa_cmax,
measure.vars = patterns("\\_Cmax"),
variable.name = "pesticide",
value.name = "cmax")
# Rm Cmax for plotting
rsqa_cmax_lf[, pesticide := sub("\\_Cmax", "", pesticide)]
```
```{r}
# Create list of plots of Cmax concentrations
pl_ov_pesticides <- function(data) {
ggplot(data,
aes(x = TSTAID, y = cmax)) +
geom_point() +
coord_flip() +
facet_wrap(. ~ Region.x,
scales = "free") +
theme_bw() +
theme(
axis.title.x = element_text(size = 16),
axis.text.x = element_text(family = "Roboto Mono",
size = 12),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.title = element_text(family = "Roboto Mono",
size = 16),
legend.text = element_text(family = "Roboto Mono",
size = 14)
)
}
ls_pesticide_plots <- split(rsqa_cmax_lf, by = "pesticide") %>%
lapply(., pl_ov_pesticides)
```
### Cmax Pesticides
:::: {.column-screen}
::: {.panel-tabset}
```{r}
#| results: asis
#| fig-width: 14
#| fig-height: 6
iwalk(ls_pesticide_plots, ~ {
cat('## ', .y, '\n\n')
print(.x)
cat('\n\n')
})
```
:::
::::